﻿Imports BUS

Public Class UserControlXoaSoTietKiem

    Private Sub txtMaSo_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtMaSo.MouseClick
        txtMaSo.Text = ""
    End Sub

    Private Sub btnXemDanhSach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXemDanhSach.Click
        LoadDanhSach()
    End Sub

    Private Sub LoadDanhSach()
        lvwDanhSachSoTietKiem.Items.Clear()
        Dim stk As New SoTietKiemBUS()
        Dim dt As New DataTable()
        dt = stk.LayThongTinDanhSachSoTietKiem()
        For i As Integer = 0 To dt.Rows.Count - 1
            Dim lv As ListViewItem = lvwDanhSachSoTietKiem.Items.Add(dt.Rows(i)("MaSo"))
            lv.SubItems.Add(dt.Rows(i)("TenLoaiTietKiem"))
            lv.SubItems.Add(dt.Rows(i)("TenKhachHang"))
            lv.SubItems.Add(dt.Rows(i)("NgayMoSo"))
            lv.SubItems.Add(dt.Rows(i)("SoDu"))
            lv.SubItems.Add(dt.Rows(i)("CMND"))
            lv.SubItems.Add(dt.Rows(i)("DiaChi"))
        Next
    End Sub
    Private Sub lvwDanhSachSoTietKiem_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvwDanhSachSoTietKiem.SelectedIndexChanged
        Dim index As Integer
        index = lvwDanhSachSoTietKiem.Items(0).Index
        If index >= 0 Then
            txtMaSo.Text = lvwDanhSachSoTietKiem.FocusedItem().SubItems(0).Text
        End If


    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim maso As Integer
        Try
            maso = Convert.ToInt32(txtMaSo.Text)
        Catch ex As Exception
            MessageBox.Show("Ma so phai la chu so")
        End Try
        Dim stkBUS As New SoTietKiemBUS()
        Dim kq As Integer
        kq = stkBUS.Xoa(maso)
        If kq <> 0 Then
            LoadDanhSach()
            MessageBox.Show("Đã xóa sổ có mã sổ " + maso.ToString())

        Else
            MessageBox.Show("Mã sổ không tồn tại")
        End If

    End Sub
End Class
